<?php
namespace Api\Controller;

use Services\Ai\AiList;
use Services\Ai\AiService;

class AiController extends AuthController
{
    /** @var AiService $service */
    private $service;

    public function _initialize()
    {
        parent::_initialize();
        $this->service = new AiService();
    }

    private function beforeChat()
    {

    }

    /**
     * 创建对话任务
     * @return void
     */
    public function chat()
    {
        $params = file_get_contents('php://input');
        $params = json_decode($params,true);
        $params['user_id'] = $this->getUserId();
        return $this->returnSuccess($this->service->setParams($params)
            ->chat());
    }

    /**
     * 返回智能体列表
     * @return void
     */
    public function list()
    {
        $this->returnSuccess(AiList::AI_LIST);
    }

    /**
     * 对话结果获取
     * @return void
     */
    public function result()
    {

        $task = $this->service->getTaskInfo($this->getUserId(), arr_get(post_params(),'task_id'));
        $this->returnSuccess($task);
    }
}

?>
